/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = wtc_tpexception.c                                  */
/*  NOTE      =                                                    */
/*  DATE      = 2015/09/30 by songbb                               */
/*******************************************************************/

#include "conntrack.h"
#include "frct_comm.h"

#include "wtc_core.h"
#include "wtc_comm.h"
#include "wtc_tpexception.h"

int wtc_tpexception_format(unsigned int ui_diagnostic
                        , unsigned int ui_tpurcode
                        , unsigned int ui_errdetail
                        , char **pp_error_msg)
{
    char arr_error_msg[64] = {'\0'};
    char arr_unknown_diagnostic[32] = {'\0'};
    char arr_tpurcode[16] = {'\0'};
    char arr_unknown_errdetail[32] = {'\0'};

    switch (ui_diagnostic) {
        case 0:
            strcat(arr_error_msg, "TPMINVAL(0)");
            break;
        case 1:
            strcat(arr_error_msg, "TPEABORT(1)");
            break;
        case 2:
            strcat(arr_error_msg, "TPEBADDESC(2)");
            break;
        case 3:
            strcat(arr_error_msg, "TPEBLOCK(3)");
            break;
        case 4:
            strcat(arr_error_msg, "TPEINVAL(4)");
            break;
        case 5:
            strcat(arr_error_msg, "TPELIMIT(5)");
            break;
        case 6:
            strcat(arr_error_msg, "TPENOENT(6)");
            break;
        case 7:
            strcat(arr_error_msg, "TPEOS(7)");
            break;
        case 8:
            strcat(arr_error_msg, "TPEPERM(8)");
            break;
        case 9:
            strcat(arr_error_msg, "TPEPROTO(9)");
            break;
        case 10:
            strcat(arr_error_msg, "TPESVCERR(10)");
            break;
        case 11:
            strcat(arr_error_msg, "TPESVCFAIL(11)");
            break;
        case 12:
            strcat(arr_error_msg, "TPESYSTEM(12)");
            break;
        case 13:
            strcat(arr_error_msg, "TPETIME(13)");
            break;
        case 14:
            strcat(arr_error_msg, "TPETRAN(14)");
            break;
        case 15:
            strcat(arr_error_msg, "TPGOTSIG(15)");
            break;
        case 16:
            strcat(arr_error_msg, "TPERMERR(16)");
            break;
        case 17:
            strcat(arr_error_msg, "TPEITYPE(17)");
            break;
        case 18:
            strcat(arr_error_msg, "TPEOTYPE(18)");
            break;
        case 19:
            strcat(arr_error_msg, "TPERELEASE(19)");
            break;
        case 20:
            strcat(arr_error_msg, "TPEHAZARD(20)");
            break;
        case 21:
            strcat(arr_error_msg, "TPEHEURISTIC(21)");
            break;
        case 22:
            strcat(arr_error_msg, "TPEEVENT(22)");
            break;
        case 23:
            strcat(arr_error_msg, "TPEMATCH(23)");
            break;
        case 24:
            strcat(arr_error_msg, "TPEDIAGNOSTIC(24)");
            break;
        case 25:
            strcat(arr_error_msg, "TPEMIB(25)");
            break;
        case 26:
            strcat(arr_error_msg, "TPMAXVAL(26)");
            break;
        default:
            snprintf(arr_unknown_diagnostic, sizeof(arr_unknown_diagnostic), "Unknown(%u)", ui_diagnostic);
            strcat(arr_error_msg, arr_unknown_diagnostic);
    }

    snprintf(arr_tpurcode, sizeof(arr_tpurcode), ":%u:", ui_tpurcode);
    strcat(arr_error_msg, arr_tpurcode);

    switch (ui_errdetail) {
        case 0:
            strcat(arr_error_msg, "TPED_MINVAL(0)");
            break;
        case 1:
            strcat(arr_error_msg, "TPED_SVCTIMEOUT(1)");
            break;
        case 2:
            strcat(arr_error_msg, "TPED_TERM(2)");
            break;
        case 3:
            strcat(arr_error_msg, "TPED_NOUNSOLHANDLER(3)");
            break;
        case 4:
            strcat(arr_error_msg, "TPED_NOCLIENT(4)");
            break;
        case 5:
            strcat(arr_error_msg, "TPED_DOMAINUNREACHABLE(5)");
            break;
        case 6:
            strcat(arr_error_msg, "TPED_CLIENTDISCONNECTED(6)");
            break;
        case 7:
            strcat(arr_error_msg, "TPED_PERM(7)");
            break;
        case 8:
            strcat(arr_error_msg, "TPED_OTS_INTERNAL(8)");
            break;
        case 9:
            strcat(arr_error_msg, "TPED_INVALID_CERTIFICATE(9)");
            break;
        case 10:
            strcat(arr_error_msg, "TPED_INVALID_SIGNATURE(10)");
            break;
        case 11:
            strcat(arr_error_msg, "TPED_DECRYPTION_FAILURE(11)");
            break;
        case 12:
            strcat(arr_error_msg, "TPED_INVALIDCONTEXT(12)");
            break;
        case 13:
            strcat(arr_error_msg, "TPED_INVALID_XA_TRANSACTION(13)");
            break;
        default:
            snprintf(arr_unknown_errdetail, sizeof(arr_unknown_errdetail), "Unknown(%u)", ui_errdetail);
            strcat(arr_error_msg, arr_unknown_errdetail);
    }

    *pp_error_msg = frstrdup(arr_error_msg);

    return FR_SUCC;
}

